package beans;

import java.util.ArrayList;
import java.util.List;

public class Page<T> {
    private Integer pagenum;
    private Integer pageStartIndex;
    private Integer pageSize;
    private Integer totalRows;
    private Integer totalPages;
    private List<T> datas;
    private List<T> parents;
    private Integer parentId;

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer  parentId) {
        this.parentId = parentId;
    }

    public List<T> getParents() {
        return parents;
    }

    public void setParents(List<T> parents) {
        this.parents = parents;
    }

    public Page() {
        this.pagenum=1;
        this.pageSize=4;
        datas=new ArrayList<>();
    }

    public Integer getPagenum() {
        return pagenum;
    }

    public void setPagenum(Integer pagenum) {
        this.pagenum = pagenum;
    }

    public Integer getPageStartIndex() {
        return (pagenum-1)*pageSize;
    }

    public void setPageStartIndex(Integer pageStartIndex) {
        this.pageStartIndex = pageStartIndex;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalRows() {
        return totalRows;
    }

    public void setTotalRows(Integer totalRows) {
        this.totalRows = totalRows;
    }

    public Integer getTotalPages() {
        if (totalRows%pageSize==0){
            totalPages=totalRows/pageSize;
        }else {
            totalPages=totalRows/pageSize+1;
        }
        return totalPages;
    }

    public void setTotalPages(Integer totalPages) {
        this.totalPages = totalPages;
    }

    public List<T> getDatas() {
        return datas;
    }

    public void setDatas(List<T> datas) {
        this.datas = datas;
    }
}
